export function setupCounter(element: HTMLButtonElement) {
  let counter = 0
  const setCounter = (count: number) => {
    counter = count
    element.innerHTML = `count is ${counter}`
  }
  setCounter(0)

  const eventSource = new EventSource("http://127.0.0.1:8000/v1/camera/video2")
  eventSource.addEventListener('update', (event) => {
    // console.log(event.data);
    const data = JSON.parse(event.data)
    //  do something with data
    setCounter(data.counter)
  })
  // close event source
  element.addEventListener('click', () =>
    eventSource.close()
  )
}
